@echo off
setlocal enabledelayedexpansion

:: 从game.ini读取项目目录
for /f "usebackq tokens=*" %%I in (`type game.ini`) do set GAME_DIR=%%I

:: 验证是否找到了项目目录
if not defined GAME_DIR (
    echo Error: Game directory not found in game.ini.
    exit /b 1
)
echo GAME_DIR: %GAME_DIR%

rem 初始化变量
set "VERSION="
set "USER_VERSION=normal"  rem 默认用户版本设为normal

rem 解析命令行参数
:loopArgs
if "%1"=="" goto :endArgs
if /i "%1"=="-v" (
    if "%2"=="" (
        echo Error: Version number must follow '-v'.
        exit /b 1
    )
    set "VERSION=%2"
    shift
)
if /i "%1"=="-u" (
    if "%2"=="" (
        echo Error: User version must follow '-u'.
        exit /b 1
    )
    set "USER_VERSION=%2"
    shift
)
shift
goto :loopArgs
:endArgs

rem 如果没有 -v 参数且只有一个参数，将其视为版本号
if "%VERSION%"=="" (
    if "%1"=="" (
        echo Error: Version number is required.
        exit /b 1
    )
    set "VERSION=%1"
)

rem 验证版本号是否已设置
if "%VERSION%"=="" (
    echo Error: Version number is required.
    exit /b 1
)

rem 设置编译配置

echo -----指定用户版本拷贝到游戏目录-----
echo User Version: %USER_VERSION%
echo Version: %VERSION%

:: 已发布的 DLL 文件路径
set "DLL_PATH=%CD%\%VERSION%\%USER_VERSION%\Mods\LE_KgPlus.dll"

:: 目标目录
set "TARGET_DIR=%GAME_DIR%\Mods"


:: 复制 DLL 文件到目标目录
echo Copying !DLL_PATH! to !TARGET_DIR!
copy "!DLL_PATH!" "!TARGET_DIR!" >nul
if %ERRORLEVEL% neq 0 (
    echo Error: Failed to copy !DLL_PATH! to !TARGET_DIR!
    exit /b 1
)

exit /b 0